﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;
using System.Collections;

using XJX.BusinessLayer;

namespace XJX.Page
{
    /// <summary>
    /// </summary>
    public class Other
    {
        public Other()
        {
        }

        //获取所有分类
        public static string Get_ALL_Category()
        {
            string result = "";

            Hashtable ht = new Hashtable();
            DataTable dt = new DataTable();

            string str = System.Configuration.ConfigurationManager.ConnectionStrings["DataConn"].ConnectionString;

            XJX.BusinessLayer.Other bs = new XJX.BusinessLayer.Other(str);

            try
            {
                dt = bs.Get_ALL_Category();//得到内存数据表

                ArrayList data = Common.DataTable2ArrayList(dt);//将上述表的数据转换成数组表形式，单行数据是哈希表格式。

                ht["rows"] = data;//将上述数据再放入一个哈希表中。

                result = XJX.BusinessLayer.JSON.Encode(ht);//将上述哈希表进行格式化
            }
            catch (SqlException e)
            {
                throw new System.Exception(e.Message);
            }
            return result;
        }

        //获取所有参数
        public static string Get_ALL_Param_For_JSON()
        {
            string result = "";

            Hashtable ht = new Hashtable();
            DataTable dt = new DataTable();

            string str = System.Configuration.ConfigurationManager.ConnectionStrings["DataConn"].ConnectionString;

            XJX.BusinessLayer.Other bs = new XJX.BusinessLayer.Other(str);

            try
            {
                dt = bs.Get_ALL_Param();//得到内存数据表

                ArrayList data = Common.DataTable2ArrayList(dt);//将上述表的数据转换成数组表形式，单行数据是哈希表格式。

                ht["rows"] = data;//将上述数据再放入一个哈希表中。

                result = XJX.BusinessLayer.JSON.Encode(ht);//将上述哈希表进行格式化
            }
            catch (SqlException e)
            {
                throw new System.Exception(e.Message);
            }
            return result;
        }

        //获取所有参数,为类赋值。
        public static ParamInfo Get_ALL_Param_For_Class()
        {
            ParamInfo pi = new ParamInfo();

            DataTable dt = new DataTable();

            string str = System.Configuration.ConfigurationManager.ConnectionStrings["DataConn"].ConnectionString;

            XJX.BusinessLayer.Other bs = new XJX.BusinessLayer.Other(str);

            try
            {
                dt = bs.Get_ALL_Param();//得到内存数据表

                foreach (DataRow dr in dt.Rows)
                {
                    pi.ID = dr["id"].ToString();
                    pi.Cname = dr["cname"].ToString();
                    pi.Aname = dr["aname"].ToString();
                    pi.Bnum = dr["bnum"].ToString();
                    pi.Lday = dr["lday"].ToString();
                    pi.Xday = dr["xday"].ToString();
                    pi.Status = dr["status"].ToString();
                    pi.Pchar = dr["pchar"].ToString();
                    pi.PIC = dr["pic"].ToString();
                    pi.Web_Url = dr["web_url"].ToString();
                    pi.dwjc = dr["dwjc"].ToString();
                    pi.MinNUM = dr["minnum"].ToString();
                    pi.YearNUM = dr["YearNUM"].ToString();
                    pi.IsUse = dr["IsUse"].ToString();
                    pi.SendStatus = dr["SendStatus"].ToString();
                    pi.UrlX = dr["UrlX"].ToString();
                    pi.CorpID = dr["CorpID"].ToString();
                    pi.PWD = dr["PWD"].ToString();
                }
            }
            catch (SqlException e)
            {
                throw new System.Exception(e.Message);
            }
            return pi;
        }

        //根据传入的过程名称，分别得到汇总报表的数据
        public static string Ad_Report_Get_Summary_List(string proc)
        {
            string str = System.Configuration.ConfigurationManager.ConnectionStrings["DataConn"].ConnectionString;

            XJX.BusinessLayer.Other bs = new XJX.BusinessLayer.Other(str);

            Hashtable ht = bs.Ad_Report_Get_Summary_List(proc);
            return XJX.BusinessLayer.JSON.Encode(ht);
        }

        public static DataRow Get_Templater_Content_From_ID(int ID)
        { 
            string str = System.Configuration.ConfigurationManager.ConnectionStrings["DataConn"].ConnectionString;

            XJX.BusinessLayer.Other bs = new XJX.BusinessLayer.Other(str);

            return ((DataTable)bs.Get_Templater_Content_From_ID(ID)).Rows[0];

        }

    }

    ////////////////////////////////////////////////////////////////////////////以下系统信息类属性

    public class ParamInfo
    {
        public string ID;
        public string Cname;
        public string Aname;
        public string Bnum;
        public string Lday;
        public string Xday;
        public string Status;
        public string Pchar;
        public string PIC;
        public string Web_Url;
        public string dwjc;
        public string MinNUM;
        public string YearNUM;
        public string IsUse;
        public string SendStatus;
        public string UrlX;
        public string CorpID;
        public string PWD;
    }

}